package com.maijinjie.common.action.easyui;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import com.maijinjie.common.action.BaseAction;
import com.maijinjie.common.bean.Pagination;
/**
 * EasyUI基本action类
 * @version 1.0
 * @author GhostarX ( 王欣逸 ) 100992995@qq.com
 * @data 2013-9-2 上午11:20:15
 */
public class EasyUIBaseAction extends BaseAction {
	/**
	 * 输出分页信息
	 * @param p 分页对象
	 * @param response
	 * @throws JsonGenerationException
	 * @throws JsonMappingException
	 * @throws IOException
	 * @version 1.0
	 * @author GhostarX ( 王欣逸 ) 100992995@qq.com 18902499340
	 * @data 2013-9-2 上午11:19:51
	 */
	public void writePagination(Pagination<?> p, HttpServletResponse response) throws JsonGenerationException, JsonMappingException, IOException{
		HashMap<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("total", p.getRowCount());
		resultMap.put("rows", null==p.getList()?new ArrayList<HashMap<String, Object>>():p.getList());
		writeHTML(new ObjectMapper().writeValueAsString(resultMap), response);
	}
}
